# -*- coding: utf-8 -*-
# @Time : 2021/9/17 14:37
# @Author : Mr  jelis
# @Email : 1402615849@qq.com
# @File : detail_page.py
# @Project : mryx_test
"""商品详情页面页面类"""
from appium.webdriver.common.mobileby import MobileBy as By
from appium.webdriver.common.mobileby import MobileBy
from page.base_page import BasePage
from utils.toast import Toast
class DetailPage(BasePage):
    """定义定位器"""
    add_shopping_locator=(By.XPATH,'//android.view.View[@content-desc="加入购物车"]')
    evaluation_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().className(\"android.widget.ImageView\")')  # 用户评价

    product_name_locator = (MobileBy.ID, 'cn.missfresh.application:id/tv_product_name')  # 详情页的商品名字
    back_locator = (MobileBy.ID, 'cn.missfresh.application:id/bv_cart_counts')  #回购物车

    zhongqiu_shangping_name_locator=(By.XPATH,'//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.ScrollView[1]/android.view.View[8]')
    to_shopping_locator=(By.XPATH,'//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/'
                                  'android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/'
                                  'android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.ImageView[3]')

    add_shop_cart_locator=(By.XPATH,'//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/'
                                'android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/'
                                'android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/'
                                'android.view.View[1]/android.view.View[1]/android.view.View[1]/'
                                'android.view.View[1]/android.view.View[3]')  #加入购物车
    click_shop_cart_locator=(By.XPATH,'//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/'
                                      'android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/'
                                      'android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/'
                                      'android.view.View[1]/android.widget.ImageView[3]')  #点击购物车
    check_detail_locator=(By.XPATH,'//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/'
                                   'android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/'
                                   'android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/'
                                   'android.view.View[1]/android.view.View[1]/android.widget.ScrollView[1]') #查看详情

    def addshopping(self):
        """点击加入购物车"""
        self.driver.find_element(*self.add_shopping_locator).click()


    def get_detailname(self):
        '''获取详情页的商品名字'''
        text = self.driver.find_element(*self.product_name_locator).text
        return text
    def get_name(self):
        '''获取中秋活动详情页的商品名字'''
        text=self.driver.find_element(*self.zhongqiu_shangping_name_locator).get_attribute("content-desc")
        return text

    def click_back(self):
        '''从详情页回到购物车页面'''
        self.driver.find_element(*self.back_locator).click()  # 点击购物车，回到购物车页面
    def to_shopping(self):
        """从中秋活动详情页进入购物车"""
        self.driver.find_element(*self.to_shopping_locator).click()
    def click_evaluation(self):
        """点击用户评价"""
        self.driver.find_element(*self.evaluation_locator).click()
    def add_shop_cart(self):
        """加入购物车"""
        self.driver.find_element(*self.add_shop_cart_locator).click()
    def click_shop_cart(self):
        """点击购物车"""
        self.driver.find_element(*self.click_shop_cart_locator).click()
    def check_detail(self):
        """点击查看详情"""
        self.driver.find_element(*self.check_detail_locator).click()

    def back(self,b=(34,64)):
        '''返回上一页'''
        self.driver.tap([b])





